package com.itCar.base.test.practical;

import com.aspose.pdf.Document;
import com.aspose.pdf.SaveFormat;
import com.itCar.base.tools.DateUtil;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileOutputStream;

/**
 * @ClassName: PDF_WORD_CHANGE
 * @Description: TODO pdf 转 word
 * @author: liuzg
 * @Date: 2022/9/13 15:58
 * @Week: 星期二
 * @Version: v1.0
 */
public class PDF_WORD_CHANGE {

    //根据不同系统环境获取不同的文件层次符
    private static final String FILE_SEPARATORS = File.separator;
    //PDF 文件地址
    private static final String PDF_PATH = "C:\\Users\\amnes\\Desktop\\b36fb77fd360aa452230ac8bbc6d5baf.pdf";
    //WORD 文件地址
    private static final String WORD_PATH = "C:\\Users\\amnes\\Desktop\\4A用户操作手册v9 - 副本.docx";

    @Test
    public void pdf_word() {
//        String old = DateUtil.getDate(0);
//        try {
//            //新建一个word文档
//            String wordPath = PDF_PATH.substring(0, PDF_PATH.lastIndexOf(".")) + ".docx";
//            FileOutputStream os = new FileOutputStream(wordPath);
//            //doc是将要被转化的word文档
//            Document doc = new Document(PDF_PATH);
//            //全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
//            doc.save(os, SaveFormat.DocX);
//            os.close();
//            //转化用时
//            System.out.println("Pdf 转 Word 共耗时：" + DateUtil.getTimeDifference(DateUtil.getDate(0), old) + "秒");
//            System.out.println("word文件地址：" + wordPath);
//        } catch (Exception e) {
//            System.out.println("Pdf 转 Word 失败...");
//            e.printStackTrace();
//        }

    }

    @Test
    public void word_pdf() {
//        String old = DateUtil.getDate(0);
//        try {
//            //新建一个pdf文档
//            String pdfPath = WORD_PATH.substring(0, WORD_PATH.lastIndexOf(".")) + ".pdf";
//            FileOutputStream os = new FileOutputStream(pdfPath);
//            com.aspose.words.Document doc = new com.aspose.words.Document(WORD_PATH); //Address是将要被转化的word文档
//            //全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
//            doc.save(os, com.aspose.words.SaveFormat.PDF);
//            os.close();
//            //转化用时
//            System.out.println("word 转 pdf 共耗时：" + DateUtil.getTimeDifference(DateUtil.getDate(0), old) + "秒");
//            System.out.println("pdf文件地址：" + pdfPath);
//        } catch (Exception e) {
//            System.out.println("word 转 pdf 失败...");
//            e.printStackTrace();
//        }
    }


    @Test
    public void test(){
        System.out.println(FILE_SEPARATORS);
    }
}
